﻿using UnityEngine;
using System.Collections;

public class AnimateFire : MonoBehaviour {

	public int materialIndex = 0;
	public Vector2 uvAnimationRate = new Vector2( 0.1f, 0.1f );
	public string textureName = "_MainTex";
	public float dur = 2.0f;
	public float lerp;
	public Material material1;
	public Material material2;

	Vector2 uvOffset = Vector2.zero;

	void Start() 
	{
	}

	void LateUpdate() 
	{
		uvOffset += ( uvAnimationRate * Time.deltaTime / 100 );

		if( renderer.enabled )
		{
			lerp = Mathf.PingPong(Time.time, dur) / dur;
			renderer.materials[ materialIndex ].SetTextureOffset( textureName, uvOffset );
			renderer.materials[ 1 ].Lerp(material1, material2, lerp);
		}
	}
}
